package com.leyou.item.clients;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient("item-service")
public interface ItemClient {
    /**
     * spu的多条件分页查询
     * @param page
     * @param rows
     * @param saleable
     * @param categoryId
     * @param brandId
     * @param id
     * @return
     */
    @GetMapping("/goods/spu/page")
    PageDTO<SpuDTO> pageQuery(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows",defaultValue = "5")Integer rows,
            @RequestParam(value = "saleable",required = false)Boolean saleable,
            @RequestParam(value = "categoryId",required = false)Long categoryId,
            @RequestParam(value = "brandId",required = false)Long brandId,
            @RequestParam(value = "id",required = false)Long id
    );

    /**
     * 根据spuId查询对应的sku信息
     * @param spuId
     * @return
     */
    @GetMapping("/goods/sku/of/spu")
    List<SkuDTO> querySkuBySpuId(@RequestParam("id")Long spuId);

    /**
     * 根据spuid查询对应的所有的规格属性或可搜索的规格属性
     * @param id
     * @param searching
     * @return
     */
    @GetMapping("/goods/spec/value")
    List<SpecParamDTO> querySpecValue(
            @RequestParam("id")Long id,
            @RequestParam(value = "searching",required = false)Boolean searching);

    /**
     * 根据品牌的id集合查询对应的品牌集合
     * @param ids
     * @return
     */
    @GetMapping("/brand/list")
    List<BrandDTO>queryBrandByIds(@RequestParam("ids") List<Long>ids);

    /**
     * 根据id集合查询对应的分类集合
     * @param ids
     * @return
     */
    @GetMapping("/category/list")
    List<CategoryDTO>queryCategoryByIds(@RequestParam("ids")List<Long>ids);

    /**
     *根据spuId查询spu的基本信息
     * @param id
     * @return
     */
    @GetMapping("/goods/spu/{id}")
    SpuDTO querySpuById(@PathVariable("id") Long id);

    /**
     * 根据spuID查询对应的spuDetail的信息
     * @param spuId
     * @return
     */
    @GetMapping("/goods/spu/detail")
    SpuDetailDTO querySpuDetailById(@RequestParam("id") Long spuId);

    /**
     * 根据品牌的id查询对应的品牌对象
     * @param id
     * @return
     */
    @GetMapping("/brand/{id}")
    BrandDTO queryBrandById(@PathVariable("id") Long id);

   @GetMapping("/spec/list")
    List<SpecGroupDTO> querySpecList(@RequestParam("id") Long cid);

    /**
     * 根据sku的id集合查询对应的sku集合
     * @param ids
     * @return
     */
    @GetMapping("/goods/sku/list")
    List<SkuDTO> querySkuByIds(
            @RequestParam("ids") List<Long> ids);

    @PutMapping("/goods/stock/minus")
    Void minusStock(@RequestBody Map<Long, Integer> cartsMap);
    /**
     * 减库存
     * @param cartMap 商品id及数量的map
     */
    @PutMapping("/goods/stock/minus")
    void deductStock(@RequestBody Map<Long, Integer> cartMap);

    /**
     * 增库存
     * @param cartsMap
     * @return
     */
    @PutMapping("/goods/stock/plus")
    void plusStock(@RequestBody Map<Long,Integer> cartsMap);
}
